﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NewsMine.DomainObjects;
using NewsMine.Storage;

namespace NewsDiscoveryEngine
{
    [Serializable]
    [Obsolete("this class is not yet used.")]
    public class FeedDeduperJob:BaseJob
    {
        //public string FeedSourceUrl { get; set; }
        //public List<FeedItem> FeedItems { get; set; }

        //public override bool ExecuteJob()
        //{
        //    if (string.IsNullOrEmpty(FeedSourceUrl))
        //        throw new ApplicationException("FeedsourceUrl can't be null or empty for deduping");

        //    if (FeedItems == null)
        //    {
        //        return true;
        //    }

        //    var results = DedupeFeeds(this.FeedSourceUrl, this.FeedItems);

        //    ProcessOutput(results);
        //    return true;
        //}

        //public static List<FeedItem> DedupeFeeds(string feedSourceUrl, List<FeedItem> feedItems)
        //{
        //    List<FeedItem> lastTimeResultedFeedItemsAgainstUrl = (List<FeedItem>) Defaults.FeedItemsStore.Get(feedSourceUrl);

        //    if (lastTimeResultedFeedItemsAgainstUrl == null)
        //        return feedItems;

        //    List<FeedItem> resultedItemsAfterDedupe = GetItemsAfterDedupe(feedItems, lastTimeResultedFeedItemsAgainstUrl);
        //    return null;
        //}

        //private static List<FeedItem> GetItemsAfterDedupe(List<FeedItem> newFeedItemsList, List<FeedItem> lastTimeResultedFeedItemsAgainstUrl)
        //{
        //    //var DuplicateLinks = (from newfdItem in newFeedItemsList
        //    //              join oldFdItem in lastTimeResultedFeedItemsAgainstUrl
        //    //              on newfdItem.Link equals oldFdItem.Link
        //    //              select new { Link = newfdItem.Link }).ToList();

        //    List<FeedItem> resultedItems = new List<FeedItem>();

        //    foreach (var newFeedItem in newFeedItemsList)
        //    {
        //        var duplicateItem = (from oldFeedItem in lastTimeResultedFeedItemsAgainstUrl
        //                             where oldFeedItem.Link == newFeedItem.Link
        //                             select oldFeedItem).FirstOrDefault();

        //        if (duplicateItem == null)
        //        {
        //            resultedItems.Add(newFeedItem);
        //        }
        //    }

        //    return resultedItems;
        //}
        public override bool ExecuteJob()
        {
            throw new NotImplementedException();
        }
    }
}
